{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Multi-Line Highlight\n",
    "====================\n",
    "This multi-line chart uses an invisible Voronoi tessellation to handle mouseover to\n",
    "identify the nearest point and then highlight the line on which the point falls.\n",
    "It is adapted from the Vega-Lite example found at\n",
    "https://bl.ocks.org/amitkaps/fe4238e716db53930b2f1a70d3401701\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# category: interactive\n",
    "\n",
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "from vega_datasets import data\n",
    "\n",
    "stocks = data.stocks.url\n",
    "\n",
    "highlight = alt.selection(type='single', on='mouseover',\n",
    "                          fields=['symbol'], nearest=True)\n",
    "\n",
    "base = alt.Chart(stocks).encode(\n",
    "    x='date:T',\n",
    "    y='price:Q',\n",
    "    color='symbol:N'\n",
    ")\n",
    "\n",
    "points = base.mark_circle().encode(\n",
    "    opacity=alt.value(0)\n",
    ").properties(\n",
    "    selection=highlight,\n",
    "    width=600\n",
    ")\n",
    "\n",
    "lines = base.mark_line().encode(\n",
    "    size=alt.condition(~highlight, alt.value(1), alt.value(3))\n",
    ")\n",
    "\n",
    "points + lines\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
